home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / 3D Buttons CDEF 1.0b6 / Source / 3D Buttons CDEF source / 3D Buttons CDEF Source Read Me next >
Text File  |  1994-12-29  |  4KB  |  95 lines

  1. 3D Buttons CDEF, by Zig Zichterman
  2. 1.0b6 29 December 1994
  3.  
  4. 3D Buttons is a control definition (CDEF) that implements the 3D interface as suggested in develop issue 15. When drawing on a 8-bit (or breater) color device (in a color GrafPort), 3D Buttons draws in grey. 3D Buttons drops to normal 2D drawing for black and white (or less than 8 bits of color).
  5.  
  6. Environment
  7. 3D Buttons is a Metrowerks CodeWarrior/CW5 project. The project does not compile under CW/4 or earlier due to some single-segment code resource link problems. I do not have Symantec C/C++ 7, so I have no idea if the CDEF can compile in Symantec environments.
  8.  
  9. The project includes the following files:
  10. CPlusPlusA4.lib
  11. MacOS.lib
  12. CDEF++.cp
  13. IsColorQDPresent.cp
  14. LCDEFCheckbox.cp
  15. LCDEFCheckboxOrRadioButton.cp
  16. LCDEFControl.cp
  17. LCDEFIconButton.cp
  18. LCDEFPushButton.cp
  19. LCDEFPushOrIconButton.cp
  20. LCDEFRadioButton.cp
  21. LColorTable.cp
  22. LDeviceLoop.cp
  23. RectT.cp
  24. RgnHandleT.cp
  25. StOffscreen.cp
  26. StSaveClip.cp
  27. StSaveColor.cp
  28. StSaveEm.cp
  29. StSaveFont.cp
  30. StSavePen.cp
  31.  
  32. Overview
  33. The source for the 3D Buttons CDEF is broken into
  34. •  the main entry function:
  35.       CDEF++.cp
  36. •  classes for 4 button variants:
  37.       LCDEFControl
  38.       LCDEFPushOrIconButton
  39.       LCDEFCheckboxOrRadioButton
  40.       LCDEFPushButton
  41.       LCDEFCheckbox
  42.       LCDEFRadioButton
  43.       LCDEFIconButton
  44. •  utility classes:
  45.       IsColorQDPresent
  46.       LColorTable
  47.       LDeviceLoop
  48.       StOffscreen
  49. •  state saver/restorers
  50.       StSaveClip
  51.       StSaveColor
  52.       StSaveEm
  53.       StSaveFont
  54.       StSavePen
  55. •  C++ encapsulation of toolbox structures
  56.       RectT
  57.       RgnHandleT
  58.  
  59. Every function call into the CDEF comes through the main entry point in CDEF++.cp. The main() function in CDEF++.cp just sets up A4 and relays the call to LCDEFControl::Main() (a static function).
  60.  
  61. LCDEFControl::Main() locks the control handle and makes sure it is valid before going any further. Main() then creates (on the stack) an object of the appropriate control kind (push button, checkbox, radio button, or icon button), and relays the call to the object's Dispatch() function.
  62.  
  63. Most of the shared work for all 4 control kinds is in LCDEFControl. Where the work required different code for different control kinds, I made a virtual function to handle the work, and implemented the function in the appropriate class.  The class hierarchy:
  64.  
  65.     LCDEFControl
  66.         LCDEFPushOrIconButton
  67.             LCDEFPushButton
  68.             LCDEFIconButton
  69.         LCDEFCheckboxOrRadioButton
  70.             LCDEFCheckbox
  71.             LCDEFRadioButton
  72.  
  73. Allows even more shared code, since push buttons and icon buttons are similar in their highlighting and rounded rect work, and checkboxes and radio buttons are similar in their script-direction sensitive placement of the radio/checkbox next to the title, and their ability to tristate.
  74.  
  75. The C++ encapsulation of RgnHandle lets me create and destroy regions without worrying about leaking a region handle, or not getting an allocation due to extraordinarily low memory. RectT is mostly a convenience wrapper, initializing the Rect to consistent values so I can avoid uninitialized variable bugs. I use higher-power versions of these and other C++ wrappers in my work and hobby code, and my code has gotten a lot more readable and a lot less buggy since.
  76.  
  77. Change History
  78. 1.0b6--28 December 1994
  79. Complete rewrite for CW/5. Now CDEF uses more features of C++, making the code cleaner and easier to support.
  80. 1.0b5--06 December 1994
  81. Lots of bug fixes!
  82. Fix useWFont bug—now actually uses window's font.
  83. Save and restore font, pen color, pen state, and clip region across draw.
  84. Clip to intersection of original clip region and device when walking device list.
  85. Honor control and window auxilliary color tables ('cctb', 'wctb' and so on) when drawing inactive/flat controls, background of checkboxes and radio buttons.
  86. Don't force 4 corners of pushbuttons to 0xDDDD.
  87. Also, use classes to save/restore the pen, color, clip region.
  88. 1.0b4--31 July 1994
  89. Bug Fix—save and restore the pen color across draws
  90. Draw 3D buttons on 4-bit devices if those devices are also greyscale, not color.
  91. 1.0b3--29 July 1994
  92. Added offscreen GWorld support so the button titles would stop that annoying flashing. Many thanks to one of my users for pointing it out.
  93. 1.0b2--20 July 1994 (never released)
  94. Call PenNormal() before starting any draw. Alerts would leave the pensize at (2,2) for the default button, which tended to make OK buttons look awful in color.
  95.